#!/bin/bash

echo "🚀 启动API自动化平台..."

# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
    echo "❌ Docker未安装，请先安装Docker"
    exit 1
fi

if ! command -v docker-compose &> /dev/null; then
    echo "❌ Docker Compose未安装，请先安装Docker Compose"
    exit 1
fi

# 创建必要的目录
mkdir -p nginx/conf.d
mkdir -p mysql/init

# 构建并启动服务
echo "📦 构建Docker镜像..."
docker-compose build

echo "🔄 启动服务..."
docker-compose up -d

echo "⏳ 等待服务启动..."
sleep 10

# 检查服务状态
echo "📊 服务状态："
docker-compose ps

echo ""
echo "✅ API自动化平台已启动！"
echo "🌐 访问地址："
echo "   - 前端界面: http://localhost"
echo "   - 后端API: http://localhost/api"
echo "   - 管理后台: http://localhost/admin"
echo "   - API文档: http://localhost/docs"
echo ""
echo "📝 常用命令："
echo "   - 查看日志: docker-compose logs -f"
echo "   - 停止服务: docker-compose down"
echo "   - 重启服务: docker-compose restart"
echo "   - 进入容器: docker-compose exec backend bash" 